//
//  HandUpTipView.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/7/31.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation

class HandUpTipView: NSView {
    
    override init(frame frameRect: NSRect) {
        super.init(frame: frameRect)
        self.setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override func draw(_ dirtyRect: NSRect) {
        
        let bezierPath = NSBezierPath.init()
        bezierPath.lineWidth = 5.0 // 线条宽度
        bezierPath.lineCapStyle = .round // 线条拐角
        bezierPath.lineJoinStyle = .round // 终点处理
        
        let startX = self.frame.origin.x
        let startY = self.frame.origin.y
        bezierPath.move(to: CGPoint.init(x: startX, y: startY))
        // 画出两条线
        bezierPath.line(to: CGPoint.init(x: startX + 5.0, y: startY + 5.0))
        bezierPath.line(to: CGPoint.init(x: startX - 5.0, y: startY + 5.0))
        
        bezierPath.close()
        // 填充颜色
        color_gray(40).set()
        dirtyRect.fill()
    }
    
    
    /*
    func makeBubble(bezierPath:NSBezierPath,bubbleRect rect:NSRect,corner:CGFloat,atPostion pos:Int) -> NSBezierPath {
        let baseAngle:CGFloat = 40
        let cornetOffWidth:CGFloat = 10
        let cornetOffHeight:CGFloat = 5
        //注angle只设定三个值0, 10，40
        /*
            0: 说明现在小三角相对于矩开来说，已看不出来了，这里直接用直角
            10:说明此时的小三解效果效好
            40:说明此时的矩开和小三角太小，需要调到40度有有效果。
            这三个值会自动的根据外部 corner 参数进行调整
         */
        let angle:CGFloat = 10
        let midCorner:Bool = false
        
        //矩形的宽和高
        let rw = rect.width
        let rh = rect.height
        //最小长度
        let minDiameter = rw > rh ? rh:rw
        
        var radius:CGFloat = 0
        
        if corner > 0 {
            radius = corner>(minDiameter/2) ?  (minDiameter/2):corner
        }
        //最小长度与圆角比
        let rate = radius/minDiameter
        
        //在下角坐标
        let leftBottom = NSPoint.init(x: rect.minX, y: rect.minY)
        let leftBottomX = NSPoint.init(x: leftBottom.x+radius, y: leftBottom.y)
        
        
        
    }
    */
    
    func setupUI() {
        self.wantsLayer = true
        //self.layer?.cornerRadius = 5
        //self.layer?.masksToBounds = true
        //self.layer?.backgroundColor = color_dark60.cgColor
        
        self.addSubview(handLab)
        handLab.snp.makeConstraints { (make) in
            make.height.equalTo(16)
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview().offset(-15)
            
        }
        self.addSubview(closeBtn)
        closeBtn.snp.makeConstraints { (make) in
            make.height.width.equalTo(20)
            make.centerY.equalToSuperview()
            make.centerX.equalToSuperview().offset(55)
        }
    }
    
    lazy var handLab: NSLabel = {
        let lab = NSLabel.label(title: "张衡正在举手", textColor: color_gray(160), font: NSFont.systemFont(ofSize: 12))
        lab.sizeToFit()
        return lab
    }()
    
    lazy var closeBtn: ZHButton = {
        let btn = ZHButton.init()
        btn.normalImage = NSImage.image(name:"icon_navtigate_close")!
        btn.zh_backgroundColor = NSColor.clear
        return btn
    }()
}
